package com.donleo.security.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;

import java.util.Date;

/**
 * <p>
 * 权限表
 * </p>
 *
 * @author liangd
 * @since 2020-12-21
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Permission implements GrantedAuthority {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 权限编号
     */
    private String code;

    /**
     * 父id  0根节点
     */
    private Integer pid;

    /**
     * 权限名
     */
    private String name;

    /**
     * 权限值
     */
    private String value;

    /**
     * 类型 1菜单 2方法
     */
    private Integer type;

    /**
     * 方法路径
     */
    private String uri;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 是否可用
     */
    private String dataEnable;

    @Override
    public String getAuthority() {
        return this.uri;
    }
}
